
import 'dart:convert';
import 'dart:typed_data';
import 'package:url_launcher/url_launcher.dart';
import 'dart:math';
import 'package:encrypt/encrypt.dart';

class util{

  static launchURL(String url) async {

    if (await canLaunch(url)) {
      await launch(url);
    } else {
      throw 'Could not launch $url';
    }
  }


  static callTelephone(String phoneNum) async {

    phoneNum = 'tel:'+phoneNum;

    if (await canLaunch(phoneNum)) {
      await launch(phoneNum);
    } else {
      throw 'Could not launch $phoneNum';
    }
  }


  /**
   * 加密
   */
  static  Future<String> encrypted(String encryptedString) async {
    Key  key =Key.fromLength(16);
    IV  iv = IV.fromLength(16);
    final  encrypter = Encrypter(AES(key, iv, mode: AESMode.cbc));
    final  encrypted = encrypter.encrypt(encryptedString);
    print("加密: ${encrypted.base64}");
    return encrypted.base64;
  }


  /**
   * 解密
   */
  static  Future<String> decrypted(String encryptedString) async {
    Key  key =Key.fromLength(16);
    IV  iv = IV.fromLength(16);
    final  encrypter = Encrypter(AES(key, iv, mode: AESMode.cbc));
    final decrypted = encrypter.decrypt(Encrypted.fromBase64(encryptedString));
    print("解密: $decrypted"); // Lorem ipsum dolor sit amet, consectetur adipiscing elit
    return decrypted;
  }







}